package org.ipti.br.tag.util;

import java.util.Calendar;

/**
 *
 * @author ipti
 */
public class EnrollmentUtil {

    public static String translateMask(String mask, String quantity) {
        try {
            Calendar current = Calendar.getInstance();

            String day = Integer.toString(current.get(Calendar.DAY_OF_MONTH));
            if (day.length() < 2)
                day = "0"+day;
            mask = mask.replace("%D", day);

            String month = Integer.toString(current.get(Calendar.MONTH)+1);
            if (month.length() < 2)
                month = "0"+month;
            mask = mask.replace("%M", month);

            String year = "";
            year += Integer.toString(current.get(Calendar.YEAR)).charAt(2);
            year += Integer.toString(current.get(Calendar.YEAR)).charAt(3);
            mask = mask.replace("%y", year);

            year = Integer.toString(current.get(Calendar.YEAR));
            mask = mask.replace("%Y", year);

            for (int i = 0; i < 4-quantity.length(); i++)
                mask = mask.replaceFirst("#", "0");
            mask = mask.replaceFirst("#", quantity);
            mask = mask.replaceAll("#", "");
        } finally {

        }
        return mask;
    }
}